package com.timoon.component.panel.tabspanel;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.googlecode.wicket.jquery.ui.Options;
import com.googlecode.wicket.jquery.ui.widget.tabs.AjaxTab;
import com.googlecode.wicket.jquery.ui.widget.tabs.TabbedPanel;
import com.timoon.app.utils.Constantor;
import com.timoon.component.panel.nav.ResourceMapper;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

public class TabsPanel extends Panel {
	private static final long serialVersionUID = 4267850653898324445L;

	public TabsPanel(String id,List<String> codes) {
		super(id);
		// TODO Auto-generated constructor stub
		
		Options options = new Options();
		options.set("collapsible", true);

		this.add(new TabbedPanel("tabs", this.newTabList(codes), options));
	}

	private List<ITab> newTabList(List<String> codes) {
		// TODO Auto-generated method stub
		final ResourceMapper mapper=(ResourceMapper) this.getSession().getAttribute(Constantor.SESSION_USER_MAPPER);
		
		List<ITab> tabs=new ArrayList<ITab>();
		
		if(codes!=null){
			for(final String code:codes){
				tabs.add(new AjaxTab(new Model(mapper.getResourceMap().get(code).getText())) {
					
					@Override
					protected WebMarkupContainer getLazyPanel(String panelId) {
						// TODO Auto-generated method stub
						return mapper.getPanelByCode(code, panelId);
					}
				});
			}
		}
		return tabs;
	}
}
